const axios = require('axios')

async function translate_baidu(text) {
    var data = {
        from: "en",
        to: "zh",
        q: text
    };

    var config = {
        method: 'post',
        url: 'https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token=24.8c0a3bba3cfc19edf32c31d3aa15fdb1.2592000.1707327005.282335-46686141',
        data: data
    };
    try {
        const response = await axios(config)
        return response.data.result.trans_result[0].dst ?? null;
    } catch (error) {
        console.log(error);
        return null; // Optionally, you can return error details or a custom error message.
    }
}


const a = [
    {
        name: "hello"
    },
    {
        name: "Minecraft"
    },
    {
        name: "Aliyun"
    },
    {
        name: "Baidu"
    },
    {
        name: "Goole"
    }
]

async function performTranslation() {
    for (let i = 0; i < a.length; i++) {
        const element = a[i].name;
        const ba = await translate_baidu(element)
        console.log(ba);
    }
}
performTranslation()